<script type="text/javascript" src="{MODULE_URL}static/js/zhanji.js"></script>
<script>
    var indexTop = Vue.component('index-top', {
        template: '#top',
        data: function () {
            return {
                msg: 'hello',
                initData: {
                    allMoney: 0,
                    allNumber: 0,
                    headlist: [],
                    daojishi: 0,
                    interval: false,
                    myyesterday: {
                        status: true,
                        checked: true
                    },
                    mytoday: {
                        status: true,
                        checked: true
                    },
                    time: {
                        h: 0, i: 0, s: 0
                    },
                    userinfo: {
                        lianxu: 0,
                        nickname: '',
                        headimgurl: ''
                    },
                    now: '00:00',
                    config:{}
                }
            };
        },
        created: function () {
            window.v = this;
            this.init();
        },
        beforeDestroy: function () {
            window.clearInterval(this.interval);
        },
        computed: {
            daojishi: function () {
                var date3 = this.initData.daojishi;
                var leave1 = date3 % (24 * 3600);
                var hours = Math.floor(leave1 / (3600));
                var leave2 = leave1 % (3600);
                var minutes = Math.floor(leave2 / (60));
                var leave3 = leave2 % (60);
                var seconds = Math.round(leave3);
                var res = '';
                if (hours > 0) {
                    res += hours + "时";
                    res += minutes + "分";
                } else if (minutes > 0) {
                    res += minutes + "分";
                }
                res += seconds + "秒";
                return res;
            },
            isQiandao: function () {
                var initData = this.initData;
                if (window.parseInt(initData.myyesterday.status) !== 1 || window.parseInt(initData.myyesterday.checked) === 1) {
                    return false;
                }
                if (initData.daojishi > 0) {
                    return false;
                }
                return true;
            },
            isPay: function () {
                var initData = this.initData;
                if (window.parseInt(initData.mytoday.status) === 1) {
                    return false;
                }
                if (initData.now >= '00:00' && initData.now < '{php echo $this->config["daka_start_time"];}') {
                    if (window.parseInt(initData.myyesterday.status) === 1) {
                        return false;
                    }
                }
                if (initData.now >= '{php echo $this->config["daka_start_time"];}' && initData.now < '{php echo $this->config["daka_end_time"];}') {
                    if (window.parseInt(initData.myyesterday.status) === 1 && window.parseInt(initData.myyesterday.checked) === 0) {
                        return false;
                    }
                }
                return true;
            }
        },
        methods: {
            init: function () {
                var self = this;
                http({
                    url: baseUrl + 'initdata'
                })
                    .then(function (res) {
                        res = res.data;
                        self.initData = res.data;
                        self.daojishi = self.initData.daojishi;
                        self.interval = window.setInterval(function () {
                            if (self.initData.daojishi <= 0) {
                                window.clearInterval(self.interval);
                            }
                            self.initData.daojishi--;
                        }, 1000);
                    });
            },
            goTo: function (path) {
                this.$router.push(path);
            },
            showTime: function () {
                
            },
            getPayData: function (money) {
                var self = this;
                if(!money && this.initData.config.pay_list) {
                    var paylist = this.initData.config.pay_list;
                    var list = [];
                    for(var i=0;i<paylist.length;i++){
                        var a = i;
                        list.push({
                            label: paylist[i].name,
                            onClick: (function (i) {
                                return function () {
                                    self.getPayData(i);
                                }
                            })(paylist[i].value)
                        });
                    }
                    weui.actionSheet(list, [
                        {
                            label: '取消',
                            onClick: function () {
                            }
                        }
                    ]);
                    return false;
                }
                
                http({
                    url: baseUrl + 'getpayinfo&money='+money
                })
                .then(function (res) {
                    res = res.data;
                    if (res.ret == 0) {
                        var data = res.data;
                        self.pay(data);
                    } else {
                        layer.open({
                            type: 2,
                            content: res.message
                        });
                        location.href = res.url;
                    }
                });
            },
            pay: function (data) {
                var self = this;
                util.pay({
                    orderFee: data.orderFee,
                    payMethod: 'wechat',
                    orderTitle: data.orderTitle,
                    orderTid: data.orderTid,
                    module: data.module,
                    success: function (result) {
                        //alert('支付成功');
                    },
                    fail: function (result) {
                        alert('fail : ' + result.message);
                    },
                    complete: function (result) {
                        location.reload();
                    }
                });
            },
            daka: function () {
                var self = this;
                http({
                    url: baseUrl + 'daka'
                })
                .then(function (res) {
                    res = res.data;
                    if (res.ret != 0) {
                        return false;
                    }
                    layer.open({
                        content: '打卡成功',
                        btn: ['确定'],
                        yes: function () {
                            location.reload();
                           /*  layer.closeAll();
                            self.getPayData(); */
                        },
                        no: function () {
                            location.reload();
                        }
                    });
                });
            },
            showRule: function () {
                var content = '<div style="text-align:left;">' +
                    '{php echo $config["rule"]}' +
                    '</div>';
                layer.open({
                    anim: 'up',
                    content: content,
                    btn: ['确认']
                });
            },
            showzhanji: function () {
                var load1 = layer.open({type: 2});
                http({
                    url: baseUrl + 'gethaibao',
                }).then(function(res){
                    layer.close(load1);
                    res = res.data;
                    var content = '<div style="position:relative;">'+'<img style="width:100%;" id="zhanjiimg" src="'+res.data+'">'+
                            '<div onclick="closeLayer()" style="border-radius:100%;position:absolute;top:-15px;right:-15px;border:1px solid #ededed;background:#000;height:30px;line-height:27px;width:30px;opacity:0.7;color:#fff;text-align:center;font-size:25px;">×</div></div>';
                        layer.open({
                            type: 1,
                            content: content,
                            anim: 'up',
                            style: 'position:fixed; left:5%; top:10%; width:90%; border: none; -webkit-animation-duration: .5s; animation-duration: .5s;'
                        });
                        var canvasHeight = $('#zhanjiimg').height();
                        $('.layui-m-layercont').css('height',canvasHeight+'px');
                        var load = layer.open({type: 2});
                        var img = new Image();
                        img.src = res.data;
                        img.onload = function () {
                            layer.close(load);
                        }
                })
            }
        }
    });
    function closeLayer () {
        layer.closeAll();
    }
    
</script>
    